import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:waimai_flutter_app/main.dart';
import '../constants.dart';
import 'FilterBar.dart';

class SearchBox extends StatelessWidget {
  const SearchBox();

  @override
  Widget build(BuildContext context) {
    return Consumer<ScrollState>(
      builder: (_, state, __) {
        return Container(
          decoration: BoxDecoration(
            color: Color.fromARGB(
                state.opacity,
                255,
                255,
                255),
          ),
          child: SafeArea(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                SizedBox(
                    height: state.scrollOffset > 0
                        ? (state.scrollOffset < flexibleBarHeight
                        ? (flexibleBarHeight - state.scrollOffset)
                        : (0))
                        : flexibleBarHeight),
                TextInput(darkness: state.deltaDarkness),
                if (state.showFilterBar) FilterBar(isSnap: true,)
              ],
            ),
          ),
        );
      },
    );
  }
}

class TextInput extends StatelessWidget {
  final int darkness;
  const TextInput({Key key, this.darkness});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.fromLTRB(margin10, margin10, margin10, 8),
      padding: EdgeInsets.symmetric(horizontal: 10),
      decoration: BoxDecoration(
        color:
        Color.fromARGB(255, 255 - darkness, 255 - darkness, 255 - darkness),
        borderRadius: BorderRadius.circular(40),
      ),
      child: TextField(
        decoration: InputDecoration(
          contentPadding: const EdgeInsets.symmetric(vertical: 6),
          enabledBorder: InputBorder.none,
          focusedBorder: InputBorder.none,
          isDense: true,
          icon: Image.asset(
            "assets/wm_nox_search_ic_poi_search_icon.webp",
            width: 22,
            height: 22,
          ),
          hintText: '火锅满减15元',
          hintStyle: const TextStyle(color: Colors.grey),
        ),
      ),
    );
  }
}

